/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package client.logic;

import com.cse.p2p.parser.*;
import java.util.List;

/**
 *
 * @author TuyetNgan
 */
public interface ClientLogicInterface {
    
    /**
     * Split a file into pieces depend on FILE_SIZE 
     * 
     * @return PIECE_SIZE
     */
    public int choosePiecesSize();
    
      /**
     * Number of pieces in file depends on FILE_SIZE
     * 
     * @param FILE_SIZE
     * @param PIECE_SIZE
     * @return Amount of pieces
     */
    public int getNumberOfPiece(long FILE_SIZE, int PIECE_SIZE);
    
    /**
     * Check in Database if piece exists
     * 
     * @param FILE_ID
     * @param PIECE_ID
     * @return TRUE if piece exists, FALSE if none 
     */
    public Boolean checkPieceInDatabase(String FILE_ID, String PIECE_ID);
    
    /**
     * Check in LocalFile if piece exists
     * 
     * @param FILE_ID
     * @param PIECE_ID
     * @return TRUE if piece exists, FALSE if none 
     */
    public Boolean checkPieceInLocalFile(String FILE_ID, String PIECE_ID);
    
    /**
     * Choose a suitable piece from peer depends on many algorithm to optimal
     *      It is find piece and peer selection strategies
     * Algorithm to find suitable piece :
     *  1) rarest first
     *  2) upload bandwidth 
     *  3) random
     * 
     * @param List<PeerInfo> : array of database
     * @param requestFile : FILE_ID request 
     * @return String[] include FILE_ID,PIECE_ID,IP address of suitable peer
     *         
     */
    String[] findPieceAndPeer( List<PeerInfo> info , String requestFile);
    
    /**
     * Choose a suitable piece from peer depends on many algorithm to optimal
     *      It is find <piece> selection strategies : <rarest first>
     *      depend on rarest piece in all peers   
     * 
     * @param data : database format   
     *     data [0][x]: FILE_ID
     *     data [1][x]: PIECE_ID
     *     data [2][x]: IP address
     *     data [3][x]: upload speed
     *    
     * @param FILE_ID
     * @return String[] include FILE_ID,PIECE_ID,IP address of suitable peer
     *         null    if no pieces is the rarest         
     */
    public String[] findPiece(String[][] data, String FILE_ID);
    
    /**
     * Choose a suitable piece from peer depends on many algorithm to optimal
     *      It is find <peer> selection strategies :   
     *      depends on bandwidth that peer allows to upload file 
     * 
     * @param array : an array of info from peers    
     *      array [2][x]: IP address
     *      array [3][x]: upload speed     
     * 
     * @return  IP address of suitable peer
     *          null if no peer has max upload bandwidth
     */
    public String findPeer(String[][] array);
    
    /**
     * Generate a random number
     * 
     * @param size : generate a random number from 0 to size
     * @return Integer : a random number
     *     
     */
    public Integer randomNumber(Integer size);
    
    /**
     * Find all pieces of file server has in Database
     * 
     * @param FILE_ID
     * @return List of all PIECE_ID of File
     */
    public String[] findFileInDatabse(String FILE_ID);
    
    /**
     * Check if all pieces of file exists
     * 
     * @param PIECE_ID
     * @return TRUE if all piece in list of peer exists, FALSE if otherwise
     */
    public Boolean checkListPieceInLocalFile(String[] PIECE_ID);
}
